<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <div id="app">
      <!-- 是父组件，可以直接传递给子孙组件 -->
      <!-- vue2里面没有响应式的 -->
      <h2>依赖注入 - <button @click="num++">btn</button></h2>
      <child></child>
    </div>

    <script src="./Vue.js"></script>
    <script>
      const Child2 = {
        inject: ["count"],
        template: `
          <div>child2组件 - {{ count }}</div>
        `,
      };

      const Child = {
        template: `
          <div>
            <div>child组件</div>
            <child2></child2>
          </div>
        `,
        components: {
          Child2,
        },
      };

      new Vue({
        el: "#app",
        data: {
          num: 30,
        },
        components: {
          Child,
        },
        provide() {
          return {
            count: this.num,
          };
        },
      });
    </script>
  </body>
</html>
